﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Web;
using MvcEngine.Core.Website;
using MvcEngine.Core;
using MvcEngine.Core.Extensions;
using MvcEngine.Mvc.Extensions;
using MvcEngine.Core.Account;
using MvcEngine.Core.Localization;
using MvcEngine.Mvc.Models;

namespace MvcEngine.Mvc.ModelBinders
{
    public class ChangePasswordModelBinder : ModelBinderBase
    {
        public override object Bind(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            HttpRequestBase request = controllerContext.HttpContext.Request;
            ChangePasswordViewModel model = new ChangePasswordViewModel();
            
            model.Password = request.Form.Get("Password");
            model.ConfirmationPassword = request.Form.Get("ConfirmationPassword");
    
            if (bindingContext.ModelState.IsValid)
            {
                if (model.Password != model.ConfirmationPassword)
                    bindingContext.ModelState.AddModelError("ConfirmationPassword", ResourceReader.Current.GetString("ConfirmPasswordIsDifferent"));

                Validate(model, controllerContext);
            }
            return model;
        }
    }
}
